-
Notifications
You must be signed in to change notification settings - Fork 121
[Shipping Labels] Apply customs form automatically after pre-fill #15853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
itsmeichigo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested and confirmed the purchase success following the steps in the PR description.
However, I can still get a purchase failure if I edit the destination address from US to non-US (more details in a comment below).
I think it'd be simpler to add a computed variable for the customs form that can be retrieved from outside the view model. That way, we can avoid the complicated reactive code and closure. WDYT?
| @Published private(set) var selectedRate: WooShippingSelectedRate? | ||
|
|
||
| @Published private var customsForm: ShippingLabelCustomsForm? | ||
| @Published private(set) var customsForm: ShippingLabelCustomsForm? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I exposed it as read-only to be trackable in unit tests. Returned it back to be just private. Checking the customsForm from package instance instead.
| /// As soon as all required info is entered, calls the `emitForm` just once | ||
| func listenForRequiredInformationCompletedUponPreFill() { | ||
| $requiredInformationIsEntered | ||
| .first { $0 == true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using first here can be risky. I still see the purchase failure with the following steps (edge case):
- Select an order with a US address as the destination.
- Edit the address to outside of the US.
- Proceed to purchase -> same error about missing customs form.

WOOMOB-734
Description
This is a follow PR to complete the recent customs data prefill feature: [Shipping Labels] Prefill customs form origin country.
The customs data became complete after a prefill without interacting with the customs form. But the
customsForminstance wasn't assigned because theonCompletioncallback was only triggered by a manual customs form dismissal.In this PR we automatically trigger the assignment callback as soon as the customs form data becomes completed. And we do that just once to handle the customs data completion by just a pre-fill.
onCompletion->onFormReadysince the callback is now not only related to the form editing completion.requiredInformationIsEnteredand triggeronFormReadyjust once when data becomes completed.Testing steps
/wcshipping/v1/label/purchase/[label id]&_method=postrequest and make sure the response contains proper customs data.RELEASE-NOTES.txtif necessary.